package com.baozun.houji.me.viewmodel

import androidx.lifecycle.MutableLiveData
import com.baozhun.mall.common.model.bean.ApiPagerResponse
import com.baozhun.mall.common.util.CacheUtil
import com.baozun.houji.me.model.bean.SystemMsgBean
import com.baozun.houji.me.network.mMeApiService
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.request

/**
 * @Title：
 * @Description：
 * @Author：xing.luo
 * @Since：2022/12/16
 * @Version：1.0.0
 */
class SystemMsgViewModel : BaseViewModel() {
    var currentPage = 1
    val systemMsgList: MutableLiveData<ApiPagerResponse<List<SystemMsgBean>>> = MutableLiveData()

    /**
     * 获取系统消息列表
     */
    fun getSystemMsgList(isRefresh: Boolean = true) {
        if (!CacheUtil.isLogin()) return
        if (isRefresh) currentPage = 1
        request({ mMeApiService.getSystemMsgList(currentPage) }, {
            systemMsgList.postValue(it)
            currentPage += 1
        }, isShowDialog = false, showErrorMsg = false)
    }
}